local jixu = fk.CreateSkill {
  name = "mini__jixu",
}

Fk:loadTranslationTable {
  ["mini__jixu"] = "击虚",
  [":mini__jixu"] = "出牌阶段限一次，你可以令所有体力值不大于你的其他角色同时猜测你的手牌中是否有【杀】。"..
  "若有角色猜错，你摸X张牌（X为猜错的角色数），然后依次弃置这些角色各一张牌，视为对其使用一张【杀】；若没有角色猜错，则你结束此阶段。",

  ["#mini__jixu"] = "击虚：令体力值不大于你的其他角色猜测你手牌中是否有【杀】",

  ["$mini__jixu1"] = "备舟则易怠，趁之而击虚。",
  ["$mini__jixu2"] = "突围可挫敌锋锐，亦可行避实之策。",
}

jixu:addEffect("active", {
  anim_type = "offensive",
  prompt = "#mini__jixu",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(jixu.name, Player.HistoryPhase) == 0 and
      table.find(Fk:currentRoom().alive_players, function (p)
        return p.hp <= player.hp and p ~= player
      end)
  end,
  card_filter = Util.FalseFunc,
  on_cost = function (self, player, data)
    return { tos = table.filter(player.room:getOtherPlayers(player), function (p)
      return p.hp <= player.hp
    end) }
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local result = room:askToJointChoice(player, {
      players = effect.tos,
      choices = {"yes", "no"},
      skill_name = jixu.name,
      prompt = "#jixu-choice:"..player.id,
      send_log = true,
    })
    local right = table.find(player:getCardIds("h"), function(id)
      return Fk:getCardById(id).trueName == "slash" end) and "yes" or "no"
    local targets = {}
    for _, p in ipairs(effect.tos) do
      local choice = result[p]
      if choice ~= right then
        table.insert(targets, p)
      end
    end
    if #targets > 0 then
      player:drawCards(#targets, jixu.name)
      for _, p in ipairs(targets) do
        if player.dead then return end
        room:doIndicate(player, {p})
        if not p.dead then
          if not p:isNude() then
            local id = room:askToChooseCard(player, {
              target = p,
              flag = "he",
              skill_name = jixu.name,
            })
            room:throwCard(id, jixu.name, p, player)
            if player.dead then return end
          end
        end
        if not p.dead then
          room:useVirtualCard("slash", nil, player, p, jixu.name, true)
        end
      end
    else
      player:endPlayPhase()
    end
  end,
})

return jixu
